package com.heima.wemadia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmNewsDto;
import com.heima.model.wemedia.dto.WmNewsListVo;
import com.heima.model.wemedia.dto.WmNewsPageReqDto;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.wemadia.service.WmNewsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自媒体文章表(WmNews)表控制层
 *
 * @author makejava
 * @since 2022-04-12 15:41:17
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    /**
     * 服务对象
     */
    @Resource
    private WmNewsService wmNewsService;

    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
     return wmNewsService.submit(dto);
   }

   @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.list(dto);
   }

   @GetMapping("/one/{id}")
    public ResponseResult getOne(@PathVariable Long id){
       WmNews wmNews = wmNewsService.queryById(id);
       return ResponseResult.okResult(wmNews);
   }

   @GetMapping("/del_news/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
      return wmNewsService.deleteNewsAndMaterial(id);
   }


   @PostMapping("/list_vo")
    public ResponseResult newsList(@RequestBody WmNewsListVo vo){
        return wmNewsService.newsList(vo);
   }

}

